#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "croututils.h"

void listarr_int(const int *base, size_t count)
{
    for (int i = 0; i < count; i++) {
	printf("%d, ", base[i]);
    }
    printf("\n");
}

void listarr_float(const float *base, size_t count)
{
    for (int i = 0; i < count; i++) {
	printf("%.2f, ", base[i]);
    }
    printf("\n");
}

void listarr_double(const double *base, size_t count)
{
    for (int i = 0; i < count; i++) {
	printf("%.2lf, ", base[i]);
    }
    printf("\n");
}


void randarr_int(int *base, size_t count)
{
    srand(time(NULL));
    for (int i = 0; i < count; i++) {
	base[i] = rand() % 1000;
    }
}

void randarr_float(float *base, size_t count)
{
    srand(time(NULL));
    for (int i = 0; i < count; i++) {
	base[i] = ((float)rand()) / RAND_MAX;
    }
}

void randarr_double(double *base, size_t count)
{
    srand(time(NULL));
    for (int i = 0; i < count; i++) {
	base[i] = ((double)rand()) / RAND_MAX;
    }
}


int compare_int(const void *addr1, const void *addr2)
{
    return *(int *)addr1 - *(int *)addr2;
}

int compare_float(const void *addr1, const void *addr2)
{
    return (*(float *)addr1 < *(float *)addr2) ? -1 : 1;
}

int compare_double (const void *addr1, const void *addr2)
{
    return (*(double *)addr1 < *(double *)addr2) ? -1 : 1;
}
